package com.derbysoft.dswitch.adapter.ihg.web.action.admin.setting.hotel;

import com.derbysoft.dswitch.adapter.ihg.common.domain.HotelMapping;
import com.derbysoft.dswitch.adapter.ihg.common.repository.HotelRepository;
import com.derbysoft.dswitch.adapter.ihg.web.action.support.PaginateActionSupport;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

public class ListAction extends PaginateActionSupport {
    @Autowired
    private HotelRepository hotelRepository;

    private HotelMapping hotelMapping;

    private HotelMapping newHotelMapping;

    @Action("list")
    public String list() {
        ActionContext.getContext().setLocale(ServletActionContext.getRequest().getLocale());
        setPaginater(hotelRepository.paginater(hotelMapping, getPaginater()));
        return SUCCESS;
    }

    public String view() {
        newHotelMapping = hotelRepository.load(hotelMapping.getId());
        return SUCCESS;
    }

    public HotelMapping getHotelMapping() {
        return hotelMapping;
    }

    public void setHotelMapping(HotelMapping hotelMapping) {
        this.hotelMapping = hotelMapping;
    }

    public HotelMapping getNewHotelMapping() {
        return newHotelMapping;
    }

    public void setNewHotelMapping(HotelMapping newHotelMapping) {
        this.newHotelMapping = newHotelMapping;
    }
}
